<template>
  <div v-loading="loading" class="store-list-main">
    <!--  辩题  -->
    <div class="title">店铺</div>

    <div class="instructions">
      <h3>说明</h3>
      <p>商户数据同步来源于享扫超管数据配置，该数据同步类型为不可编辑，不支持门店添加，如果需要添加门店，请到享扫。</p>
    </div>

    <!-- filter start -->
    <el-form ref="filterForm" :inline="true" :model="filterForm" label-width="120px" size="small">
      <el-form-item
        prop="name"
        label="店铺名称："
      >
        <el-input
          v-model="filterForm.name"
          placeholder="请输入"
          clearable
          class="app-w-350"
          @keyup.enter.native="submitFilterForm"
        />
      </el-form-item>
      <el-form-item
        prop="serial"
        label="店铺编号："
      >
        <el-input
          v-model="filterForm.serial"
          placeholder="请输入"
          clearable
          class="app-w-350"
          @keyup.enter.native="submitFilterForm"
        />
      </el-form-item>
      <div>
        <el-form-item label=" ">
          <el-button type="primary" round @click="submitFilterForm">查询店铺</el-button>
          <el-button round @click="resetFilterForm">重置条件</el-button>
        </el-form-item>
      </div>
    </el-form>
    <!--  列表  -->
    <div v-if="!loading&&list.length===0" class="empty-tips">
      查询暂无数据
    </div>
    <el-row v-else :gutter="16" type="flex">
      <el-col v-for="item in list" :key="item.serial" :md="12" :lg="8" :xl="6">
        <el-card :body-style="{ padding: '20px 15px'}" shadow="hover">
          <div class="flex-x-start-center">
            <el-avatar
              class="logo"
              size="medium"
              :src="fileBaseUrl + item.icon"
              fit="fill"
            />
            <div class="name app-ellipsis-l1">
              {{ item.name }}
            </div>
          </div>
          <div class="info app-ellipsis-l1">编号：{{ item.serial }}</div>
          <div class="info app-ellipsis-l1">地址：{{ item.provinceCode + item.cityCode + item.areaCode + item.address }}
          </div>
          <div class="info app-ellipsis-l1">电话：{{ item.mobilePhone || '-' }}</div>
          <div class="handle-group">
            <el-button type="text" size="mini" icon="el-icon-edit" circle @click.native="handleEdit(item)">编辑
            </el-button>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!--分页-->
    <PaginationDirection
      v-if="paginationConfig.total!==0"
      :config.sync="paginationConfig"
      @sizesChange="fetchData"
      @pageChange="fetchData"
    />

    <!--组件-->
    <MchStoreFormDialog ref="mchStoreFormDialog" />
  </div>
</template>

<script>
import MchStoreFormDialog from './components/MchStoreFormDialog'
import { mapGetters } from 'vuex'
import { shopPage } from '@/api/mch/shop'

export default {
  components: {
    MchStoreFormDialog
  },
  data() {
    return {
      // 配置
      // 分页配置
      paginationConfig: {
        direction: 'center', // 分页位置
        layout: 'total, sizes, prev, pager, next, jumper', // 分页类型
        pageSizes: [10, 20], // 分页pages
        total: 0,
        page: 1, // 页数-默认1
        pageSize: 10 // 每页条数-默认10
      },
      // 状态
      loading: false,
      // 数据
      filterForm: {
        businessId: null,
        name: null,
        pageNum: 1,
        pageSize: 10,
        serial: null
      },
      list: []
    }
  },
  computed: {
    ...mapGetters(['fileBaseUrl'])
  },
  watch: {},
  beforeCreate() {
  },
  created() {
    // 定义全局刷新方法
    this.$root.$on('refreshMchStoreList', () => this.fetchData())
  },
  beforeMount() {
  },
  mounted() {
    this.fetchData()
  },
  beforeUpdate() {
  },
  update() {
  },
  activated() {
  },
  deactivated() {
  },
  beforeDestroy() {
    this.$root.$off('refreshMchStoreList')
  },
  destroyed() {
  },
  methods: {
    /**
     * 数据组
     */
    // 获取列表
    fetchData(
      page = this.paginationConfig.page,
      pageSize = this.paginationConfig.pageSize
    ) {
      // 请求参数
      const params = Object.assign({}, this.filterForm)
      params.pageNum = page
      params.pageSize = pageSize
      params.businessId = this.$route.query.mchId
      // 清除多余字段
      for (const key in params) {
        if (this.$isNull(params[key])) delete params[key]
      }
      // 请求
      this.loading = true
      shopPage({ data: params })
        .then(res => {
          this.list = res.data.list
          this.paginationConfig.total = res.data.total
          this.paginationConfig.page = res.data.pageNum
        })
        .finally(() => {
          this.loading = false
        })
    },
    /**
     * 按钮组
     */
    // 查询
    submitFilterForm() {
      this.fetchData(1)
    },

    // 重置
    resetFilterForm() {
      this.$refs.filterForm.resetFields()
    },

    // 编辑
    handleEdit(row) {
      this.$refs.mchStoreFormDialog.open({ mode: 'edit', row }).then(() => {
        this.fetchData()
      })
    }
    /**
     * 状态组
     */
    /**
     * 方法组
     */
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.store-list-main {

  /*reset*/
  .el-row {
    flex-wrap: wrap;

    .el-col {
      margin-bottom: 16px;
      height: 100%;
    }
  }
  .title{
    height: 50px;
    line-height: 50px;
    font-size: 18px;
    font-weight: bold;
  }

	.instructions {
		border: 1px solid #dcdfe6;
		padding: 16px;
		box-sizing: border-box;
		margin: 15px 0 50px;
		h3{
			margin: 0;
		}
	}

  /*卡片*/
  .el-card {
    position: relative;
    border-radius: 20px;

    .handle-group {
      //display: none;
      position: absolute;
      right: 10px;
      top: 5px;
    }

    //:hover .handle-group {
    //  display: block;
    //}

    /*title*/
    .title {
      height: 50px;
      line-height: 50px;
      font-size: 18px;
      font-weight: bold;
    }

    /*card*/
    .logo {
      flex: 0 0 44px;
      height: 44px;
      margin-right: 10px;
      border-radius: 50%;
    }

    .name {
      font-size: 18px;
    }

    .info {
      margin-top: 10px;
      font-size: 14px;
      color: #909399;
    }
  }

  /*空提示*/
  .empty-tips {
    text-align: center;
    font-size: 12px;
    padding-top: 100px;
  }
}
</style>
